package com.libinyn.base.pms.controller.sys;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.libinyn.base.pms.common.utils.Result;
import com.libinyn.base.pms.controller.AbstractController;
import com.libinyn.base.pms.entity.sys.SysLogEntity;
import com.libinyn.base.pms.serivce.sys.SysLogService;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;


/**
 * 系统日志
 * @fileName: SysLogController.java
 * @author: bin.li01
 * @date: 2017/12/13 22:18 
 * @version: v1.0.0
 */
@Controller
@RequestMapping("/sys/log")
public class SysLogController extends AbstractController{

	@Resource
	private SysLogService sysLogService;
	
	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping("/list")
	@RequiresPermissions("sys:log:list")
	public Result list(SysLogEntity sysLogEntity,PageInfo<SysLogEntity> pageInfo){


		//如果不是超级管理员，则只查询自己创建的角色列表
		List<SysLogEntity> sysLogEntities;
		if (StringUtils.isBlank(sysLogEntity.getIp())){
			sysLogEntity.setIp(null);
		}
		try {
			PageHelper.startPage(pageInfo.getPageNum(), pageInfo.getPageSize());
			sysLogEntities = sysLogService.select(sysLogEntity);
			pageInfo = new PageInfo<SysLogEntity>(sysLogEntities);

		} catch (Exception e) {
			logger.error("查询数据失败！",e);
			return Result.error("查询数据失败！");
		}

		return Result.ok().put("page", pageInfo);
	}
	
}
